package com.wulwu.caffeine.controller;

import com.wulwu.caffeine.entity.OrderActionCode;
import com.wulwu.caffeine.service.OrderCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderCacheController {

    @Autowired
    private OrderCacheService orderCacheService;

    /**
     * 查询指定编码说明
     * @param actionCode
     * @return
     */
    @GetMapping(value = "queryActionCode")
    public Object queryActionCode(@RequestParam(value = "actionCode") Integer actionCode){
        OrderActionCode orderActionCode = orderCacheService.queryActionCode(actionCode);
        return orderActionCode;
    }

    /**
     * 初始化所有编码缓存
     * @return
     */
    @GetMapping(value = "initActionCodeCache")
    public Object initActionCodeCache(){
        return orderCacheService.initActionCodeCache();
    }

    /**
     * 获取所有编码说明
     * @return
     */
    @GetMapping(value = "queryAllActionCode")
    public Object queryAllActionCode(){
        return orderCacheService.queryAllActionCode();
    }

    /**
     * 获取当前缓存结构
     * @return
     */
    @GetMapping(value = "actionCodeCache")
    public Object actionCodeCache(){
        return orderCacheService.actionCodeCache();
    }

    /**
     * 指定删除
     * @param actionCode
     * @return
     */
    @GetMapping(value = "delActionCodeCache")
    public Object delActionCodeCache(@RequestParam(value = "actionCode") Integer actionCode){
        orderCacheService.delActionCodeCache(String.valueOf(actionCode));
        return null;
    }

    /**
     * 批量删除
     * @param keys
     * @return
     */
    @GetMapping(value = "batchClearActionCodeCache")
    public Object batchClearActionCodeCache(@RequestBody List<String> keys){
        orderCacheService.batchClearActionCodeCache(keys);
        return null;
    }

    /**
     * 清楚缓存
     * @return
     */
    @GetMapping(value = "clearActionCodeCache")
    public Object clearActionCodeCache(){
        orderCacheService.clearActionCodeCache();
        return null;
    }
}
